package com.example.demo.test.leetcode.day1218;

import java.util.Arrays;

public class Solution1218 {
    public static void main(String[] args) {
        // System.out.println(findTheDifference("abcd", "adbcd"));
        //System.out.println(findRepeatNumber(new int[]{2, 3, 1, 0, 2, 5, 3}));
        System.out.println(replaceSpace("We are happy."));
    }

//    public static char findTheDifference(String s, String t) {
//        char[] charArray1 = s.toCharArray();
//        char[] charArray2 = t.toCharArray();
//        Arrays.sort(charArray1);
//        Arrays.sort(charArray2);
//        for (int i = 0; i < charArray1.length; i++) {
//            if (charArray1[i] != charArray2[i])
//                return charArray2[i];
//        }
//        return charArray2[charArray2.length - 1];
//    }

    // ascii🐎
    public static char findTheDifference(String s, String t) {
        int as = 0, at = 0;
        for (int i = 0; i < s.length(); i++) {
            as += s.charAt(i);
        }
        for (int i = 0; i < t.length(); i++) {
            at += t.charAt(i);
        }
        return (char) (at - as);
    }

    public static int findRepeatNumber(int[] nums) {
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == nums[i + 1])
                return nums[i];
        }
        return 0;

    }


    public static String replaceSpace(String s) {

        return s.replace(" ","%20");
    }


}
